﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace zyc
{
    public class PublishMagazineEventArgs : EventArgs
    {
        private readonly string m_magazineName;
        private readonly DateTime m_publishDate;

        public PublishMagazineEventArgs(string magazineName, DateTime publishDate)
        {
            m_magazineName = magazineName;
            m_publishDate = publishDate;
        }

        public string MagazineName
        {
            get { return m_magazineName; }
        }

        public DateTime MagazineDate
        {
            get { return m_publishDate; }
        }
    }


    public class Publisher  //发行者
    {

        public delegate void PublishMagazineEventHandler(object sender, PublishMagazineEventArgs e);

        public event PublishMagazineEventHandler PublishMagazine;

        public virtual void OnPublishMagazine(PublishMagazineEventArgs e)
        {
            PublishMagazineEventHandler handler = PublishMagazine;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        public void PublisIssue(string name, DateTime date)
        {
            Console.WriteLine("发行刊物");

            OnPublishMagazine(new PublishMagazineEventArgs(name, date));
        }

    }

    public class Subcriber  //订阅者
    {
        private readonly string name;

        public Subcriber(string name)
        {
            this.name = name;
        }

        public void Receive(object sender,PublishMagazineEventArgs e)
        {
            Console.WriteLine(e.MagazineDate+":"+name + "收到" + e.MagazineName + "刊物");

        }

    }
}
